from typing import List

"""
超时了，时间复杂度为 O(NK)，N为A数组长度
可以通过差分数组来实现把K次的翻转转化成常数级的操作
"""


class Solution:
    def minKBitFlips(self, A: List[int], K: int) -> int:
        count = 0
        index = 0

        def fz(start):

            end = start + K
            if end > len(A):
                return
            for i in range(start, end):
                if A[i]:
                    A[i] = 0
                else:
                    A[i] = 1

        while index < len(A):
            if A[index] == 0:
                fz(index)
                print(A)
                count += 1
                print(index)

            index += 1

        if all(A):
            return count
        else:
            return -1

